package hpp.tencentTest;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 把一个字符串的大写字母放到字符串的后面，各个字符的相对位置不变，且不能申请额外的空间。
 * Created by hpp on 2017/9/12.
 */
public class turnLocation {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNext()) {
            char[] str = scan.next().toCharArray();
            int len = str.length;
            //O(n²)
            for (int j = 0; j < len - 1; j++) {
                for (int i = len - 1; i > j; i--) {
                    if (str[i] <= 'z' && str[i] >= 'a' && str[i - 1] <= 'Z' && str[i - 1] >= 'A')
                        str = swap(str, i - 1, i);
                }
            }

            System.out.println(String.valueOf(str));
        }
    }

    public static char[] swap(char[] str, int num1, int num2) {
        char temp = str[num1];
        str[num1] = str[num2];
        str[num2] = temp;
        return str;
    }


    //其他思路
    //思路1
    public static String getResult(String str) {
        return str.replaceAll("[A-Z]", "") + str.replaceAll("[a-z]", "");
    }

    //思路2 循环两遍，第一遍输出小写，第二遍输出大写
    public static void getResult2(char[] A) {
        for (char item : A) {
            if (Character.isLowerCase(item))
                System.out.print(item);
        }
        for (char item : A) {
            if (Character.isUpperCase(item))
                System.out.print(item);
        }
    }

}
